package JZOffer;

/**
 * @author Lw中
 * @date 2021/8/16 22:49
 */
public class Jz21 {

    // Jz21.调整数组顺序使奇数位于偶数前面

    public int[] exchange(int[] nums) {
        // 方法1：快慢双指针
        int slow = 0, fast = 0;
        while (fast < nums.length) {
            if (nums[fast] % 2 == 1) {
                int temp = nums[slow];
                nums[slow] = nums[fast];
                nums[fast] = temp;
                slow++;
            }
            fast++;
        }
        return nums;
    }
}
